package com.china08.yxyapi.api.manage.stu.mystudy.tifenbao.scoreimprove;

import java.text.ParseException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.huixue.YxyHuixuePlan;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.huixue.YxyHuixuePlanRepository;
import com.china08.yxyapi.service.tifenbao.TifenbaoKnowLstService;

import io.swagger.annotations.ApiOperation;

/**
 * 学习计划-计划详情
 * 
 */
@CrossOrigin
@RestController
public class TifenbaoKnowLstlController extends YxyApiBaseController {
    @Autowired
    private YxyHuixuePlanRepository yxyHuixuePlanRepository;
    @Autowired
    private TifenbaoKnowLstService tifenbaoKnowLstService;

    @ResponseBody
    @ApiOperation(value = "学习计划 计划详情")
    @RequestMapping(value = "/api_yw/manage/stu/mystudy/tifenbao/scoreimprove/plan/detail/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel)
            throws ParseException {
        YxyHuixuePlan plan = yxyHuixuePlanRepository.findById(reqModel.planId);
        RespModel model = new RespModel();
        model.planId = reqModel.planId;
        model.charName = plan.getBookContentName();
        model.status = plan.getStatus();
        // 开始时间
        Integer beginDate = plan.getBeginDate();
        String beginDateString = null;
        if (beginDate != null && beginDate != 0) {
            beginDateString = String.valueOf(beginDate);
            beginDateString = beginDateString.substring(0, 4) + "-" + beginDateString.substring(4, 6) + "-"
                    + beginDateString.substring(6);
        }
        // 结束时间
        Integer endDate = plan.getEndDate();
        String endDateString = null;
        if (endDate != null && endDate != 0) {
            endDateString = String.valueOf(endDate);
            endDateString = endDateString.substring(0, 4) + "-" + endDateString.substring(4, 6) + "-"
                    + endDateString.substring(6);
        }
        model.startDate = beginDateString;
        model.endDate = endDateString;
        // 得到章节下面所对应的所有小节及知识点情况
        List<Object[]> objs = tifenbaoKnowLstService.list(reqModel.planId, reqModel.studentId);// 学习计划中章节下面所对应的所有小节及知识点情况
        model.studObjects = objs;
        return model;

    }

    protected static class RespModel extends YxyApiRespModel {
        // 计划id
        public String planId;
        // 学习计划中选择的章
        public String charName;
        // 计划状态0已截止1进行中
        public Integer status;
        // 起始时间
        public String startDate;
        // 截止时间
        public String endDate;
        // 学习计划中章节下面所对应的所有小节及知识点情况 ：Object[0]节名称，Object[1]是CharpterModel对象
        public List<Object[]> studObjects;
    }

    protected static class ReqModel extends YxyApiReqModel {
        // 计划id
        public String planId;
        // 学生id
        public String studentId;
    }

    /**
     * 知识点内容
     * 
     * @author Administrator
     *
     */
    public static class CharpterModel {
        // YxyHuixuePlan对象的id
        public String id;
        // 知识点pkid
        public String pkid;
        // 知识点名称
        public String knowName;
        // 关注等级
        public Integer attention;
        // 知识点闯关次数
        public Integer mubiao;
        // 知识点完成闯关次数
        public Integer wancheng;
        // 知识点id
        public String knowId;
    }
}
